package Test1;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ex3 extends JFrame {

	private JPanel contentPane;
	private JLabel lblNewLabel;
	private JTextField st;
	private JLabel lblNewLabel_1;
	private JTextField st1;
	private JButton btnNewButton;
	private JScrollPane scrollPane;
	private JTextArea result;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ex3 frame = new ex3();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ex3() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getLblNewLabel());
		contentPane.add(getSt());
		contentPane.add(getLblNewLabel_1());
		contentPane.add(getSt1());
		contentPane.add(getBtnNewButton());
		contentPane.add(getScrollPane());
	}

	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("범위");
			lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
			lblNewLabel.setBounds(33, 28, 57, 15);
		}
		return lblNewLabel;
	}

	private JTextField getSt() {
		if (st == null) {
			st = new JTextField();
			st.setBounds(102, 25, 57, 21);
			st.setColumns(10);
		}
		return st;
	}

	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("~");
			lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
			lblNewLabel_1.setBounds(171, 28, 31, 15);
		}
		return lblNewLabel_1;
	}

	private JTextField getSt1() {
		if (st1 == null) {
			st1 = new JTextField();
			st1.setBounds(214, 25, 57, 21);
			st1.setColumns(10);
		}
		return st1;
	}

	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("실행");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					long start = System.currentTimeMillis();
					
					int x = Integer.parseInt(st.getText());
					int y = Integer.parseInt(st1.getText());
					
					if(x>y){
						int temp =x;
						x=y;
						y=temp;
					}
					if(x<=y){
						for(int i=x;i<=y;i++){
							if(i%2 == 0){
								if(i==2){
								result.append("\n"+i);
							}	
						}else if(i%3 == 0){
							if(i==3){
								result.append("\n"+i);
							}
						}else if(i%5==0){
							if(i==5){
								result.append("\n"+i);
							}
						}else if(i%7==0){
								if(i==7){
									result.append("\n"+i);
								}
							}
						else{
							result.append("\n"+i);
						}
						}
					}
					
				
			}
			});
			btnNewButton.setBounds(283, 24, 97, 23);
		}
		return btnNewButton;
	}

	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(12, 59, 372, 136);
			scrollPane.setViewportView(getResult());
		}
		return scrollPane;
	}

	private JTextArea getResult() {
		if (result == null) {
			result = new JTextArea();
		}
		return result;
	}
}
